#ifndef RING_BUFFER_H
#define RING_BUFFER_H

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

//定义内存分配
#define RING_BUFFER_MALLOC malloc
#define RING_BUFFER_FREE free

enum {
    RING_BUFFER_OK = 0,        // 成功
    RING_BUFFER_ERROR = -1,    // 错误
    RING_BUFFER_FULL = -2,     // 缓冲区满
    RING_BUFFER_EMPTY = -3,     // 缓冲区空
    //缓冲区空间不足
    RING_BUFFER_NO_SPACE = -4,
    //读取数据不足
    RING_BUFFER_READ_INSUFFICIENT = -5
};

// 定义环形缓冲区结构体
typedef struct {
    uint8_t *head;         // 数据缓冲区头指针
    uint8_t *tail;         // 数据缓冲区头指针尾指针
    uint8_t *read;         // 数据读指针
    uint8_t *write;        // 数据写指针
    size_t max_size;     // 缓冲区大小
} ring_buffer_t;

ring_buffer_t *ring_buffer_create(size_t size);
int ring_buffer_delete(ring_buffer_t *ring_buffer);
int ring_buffer_write(ring_buffer_t *ring_buffer, const uint8_t *data, size_t size);
int ring_buffer_read(ring_buffer_t *ring_buffer, uint8_t *data, size_t size);
size_t ring_buffer_available_data(ring_buffer_t *ring_buffer);
size_t ring_buffer_available_space(ring_buffer_t *ring_buffer)

#endif